package com.test.enumtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 5.疾病及其与营养需求的关系
 */
public enum EnumSGA5 {

    // 1.主要相关诊断
    ANSWER1_1(1, 1, "无"),
    ANSWER1_2(2, 1, "癌症"),
    ANSWER1_4(4, 1, "AIDS"),
    ANSWER1_8(8, 1, "肺源性或心源性恶液质"),
    ANSWER1_16(16, 1, "出现褥疮"),
    ANSWER1_32(32, 1, "开放伤口或瘘"),
    ANSWER1_64(64, 1, "存在创伤"),

    ;

    public final int id;
    public final int score;
    public final String name;

    EnumSGA5(int id, int score, String name) {
        this.id = id;
        this.score = score;
        this.name = name;
    }

    /**
     * 获取答案列表 1.主要相关诊断
     *
     * @return
     */
    public static List<Map<String, Object>> getAnswerList() {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(createMap(1));
        list.add(createMap(2));
        list.add(createMap(4));
        list.add(createMap(8));
        list.add(createMap(16));
        list.add(createMap(32));
        list.add(createMap(64));
        return list;
    }

    /**
     * 根据id获取枚举
     *
     * @param id
     * @return
     */
    public static EnumSGA5 get(int id) {
        switch (id) {
            case 1:
                return ANSWER1_1;
            case 2:
                return ANSWER1_2;
            case 4:
                return ANSWER1_4;
            case 8:
                return ANSWER1_8;
            case 16:
                return ANSWER1_16;
            case 32:
                return ANSWER1_32;
            case 64:
                return ANSWER1_64;
            default:
                return null;
        }
    }

    /**
     * 根据id获取分数
     *
     * @param id
     * @return
     */
    public static int getScore(int id) {
        EnumSGA5 en = EnumSGA5.get(id);
        if (en != null) {
            return en.score;
        } else {
            return -1;
        }
    }

    private static Map<String, Object> createMap(int id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", EnumSGA5.get(id).id);
        map.put("name", EnumSGA5.get(id).name);
        map.put("score", EnumSGA5.get(id).score);
        return map;
    }
}
